package keyboaUtil.commonUtil.regular;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 2B键盘
 * @date 2018-03-20 23:22
 * @desc 匹配正则表达式引擎
 * @version 1.0
 **/
public class RegularEngine {

    /**
     * 匹配数据
     *
     * @param str
     * @param regex
     * @param len
     * @return String
     */
    public static String run(String str, String regex,int len) {
        StringBuffer stringBuffer = new StringBuffer();
        Matcher matcher = Pattern.compile(regex).matcher(str);
        while (matcher.find()) {
            stringBuffer.append(matcher.group(len));
        }
        return new String(stringBuffer);
    }

    /**
     * 匹配数据
     * @param str
     * @param regex
     * @return String
     */
    public static String run(String str, String regex) {
        StringBuffer stringBuffer = new StringBuffer();
        Matcher matcher = Pattern.compile(regex).matcher(str);
        while (matcher.find()) {
            stringBuffer.append(matcher.group(1));
        }
        return new String(stringBuffer);
    }

}
